<?php

namespace App\Http\Requests\Strator;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateStratorPermissionRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'id'=>'required|integer|min:0',
            'pid'=>'required|integer|min:0',
            'permission_name'=>'required|string|min:1|max:30',
            'module_name'=>'sometimes|string|max:30',
            'route'=>[
                'sometimes',
                'string',
                'max:255',
                Rule::unique('strator_permissions','route')->ignore($this->id??0),
            ],
            'sort'=>'required|integer',
            'icon'=>'sometimes|string|max:255',
            'type'=>'required|integer|min:1|max:100',
            'permission_action'=>'sometimes|string|max:255',
            'status'=>'required|integer|min:0|max:1',
        ];
    }
    /**
     * Get the error messages for the defined validation rules.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'id.required'=>'id参数为必传',
            'id.integer'=>'id参数错误',
            'id.min'=>'id参数错误',

            'pid.required' => 'pid参数为必传',
            'pid.integer' => 'pid参数不正确',
            'pid.min' => 'pid参数不正确',

            'permission_name.required' => '权限名称为必填',
            'permission_name.string' => '权限名称只能是字符串类型',
            'permission_name.min' => '权限名称长度要在1-30位之间',
            'permission_name.max' => '权限名称长度要在1-30位之间',

            'module_name.string' => '模块名称只能是字符串类型',
            'module_name.max' => '模块名称长度不能超过30位',

            'route.string' => 'route只能是字符串类型',
            'route.max' => 'route长度不能超过255位',
            'route.unique' => 'route已存在',

            'sort.integer' => '排序值只能是整数',

            'icon.string' => '图标的值必须是字符串类型',
            'icon.max' => '图标字符的长度不能超过255位',

            'type.required' => '类型参数为必传',
            'type.integer' => '类型参数只能是整数',
            'type.min' => '类型参数的大小要在1-100之间',
            'type.max' => '类型参数的大小要在1-100之间',

            'permission_action.string' => 'permission_action只能是字符串类型',
            'permission_action.max' => 'permission_action字符的长度不能超过255位',

            'status.required' => '状态为必传',
            'status.integer' => '权限状态只能是0或1',
            'status.min' => '权限状态只能是0或1',
            'status.max' => '权限状态只能是0或1',

        ];
    }
}
